package com.wchen.gdoc.generate.config;

import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

/**
 * 项目核心配置
 *
 * @author  wchen
 * @date    2019/11/11
 */
public class CoreConfig {
    private List<String> typeStructureResolverChain = new ArrayList<>();
    private List<String> docTypeAnalysisChain = new ArrayList<>();
    private String paramValueProducer;
    private String dataProcessor;
    private Boolean debugEnable;

    protected static CoreConfig initCoreConfig(Properties prop){
        CoreConfig coreConfig = new CoreConfig();
        String docAnalysisChainConfig = prop.getProperty(Constant.CORE_DOC_ANALYSIS_CHAIN);
        String paramValueProducer = prop.getProperty(Constant.CORE_PARAM_PRODUCER);
        String dataProcessorConfig = prop.getProperty(Constant.CORE_DATA_PROCESSOR);
        Boolean debugEnable = Boolean.valueOf(prop.getProperty(Constant.CORE_DEBUG_ENABLE));
        if(!StringUtils.isEmpty(docAnalysisChainConfig)){
            coreConfig.setDocTypeAnalysisChain(Arrays.asList(docAnalysisChainConfig.split(";")));
        }
        if(!StringUtils.isEmpty(paramValueProducer)){
            coreConfig.setParamValueProducer(paramValueProducer);
        }
        if(!StringUtils.isEmpty(dataProcessorConfig)){
            coreConfig.setDataProcessor(dataProcessorConfig);
        }

        coreConfig.setDebugEnable(debugEnable);
        return coreConfig;
    }

    protected void validityCheck(){

    }

    public List<String> getDocTypeAnalysisChain() {
        return docTypeAnalysisChain;
    }

    public void setDocTypeAnalysisChain(List<String> docTypeAnalysisChain) {
        this.docTypeAnalysisChain = docTypeAnalysisChain;
    }

    public List<String> getTypeStructureResolverChain() {
        return typeStructureResolverChain;
    }

    public void setTypeStructureResolverChain(List<String> typeStructureResolverChain) {
        this.typeStructureResolverChain = typeStructureResolverChain;
    }

    public String getParamValueProducer() {
        return paramValueProducer;
    }

    public void setParamValueProducer(String paramValueProducer) {
        this.paramValueProducer = paramValueProducer;
    }

    public String getDataProcessor() {
        return dataProcessor;
    }

    public void setDataProcessor(String dataProcessor) {
        this.dataProcessor = dataProcessor;
    }

    public Boolean getDebugEnable() {
        return debugEnable;
    }

    public void setDebugEnable(Boolean debugEnable) {
        this.debugEnable = debugEnable;
    }
}
